/*
 * @Author: szx
 * @Date: 2021-11-01 13:38:38
 * @LastEditTime: 2021-11-01 14:03:35
 * @Description:
 * @FilePath: \leetcode\700-799\733\733.cpp
 */
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

class Solution {
   public:
    const int dx[4] = {1, 0, 0, -1};
    const int dy[4] = {0, 1, -1, 0};
    vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc,
                                  int newColor) {
        const int curColor = image[sr][sc];
        if (newColor == curColor) {
            return image;
        }
        int n = image.size(), m = image[0].size();
        queue<pair<int, int>> que;
        que.emplace(sr, sc);
        image[sr][sc] = newColor;
        while (!que.empty()) {
            int x = que.front().first, y = que.front().second;
            que.pop();
            for (int i = 0; i < 4; i++) {
                int mx = x + dx[i], my = y + dy[i];
                if (mx >= 0 && mx < n && my >= 0 && my < m &&
                    image[mx][my] == curColor) {
                    que.emplace(mx, my);
                    image[mx][my] = newColor;
                }
            }
        }
        return image;
    }
};
int main() { return 0; }